package study.springboot.mvc.controller._1_binding;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import study.eggs.result.Result;
import study.eggs.result.Results;

@Slf4j
@RestController
@RequestMapping("/binding")
public class MultipartController {

    @RequestMapping("/requestPart")
    public Result requestParam(@RequestParam("name") String name,
                               @RequestPart("file") MultipartFile file) {
        log.info("name= {}", name);

        String fileName = file.getOriginalFilename();
        String contentType = file.getContentType();
        log.info("file_name= {}", fileName);
        log.info("content_type= {}", contentType);
        return Results.ok();
    }
}
